package com.five.admin.utils;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class MqUtils{

    private static RabbitTemplate template;

    @Resource
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init(){
        template = this.rabbitTemplate;
    }

    public static void send(String exchange, String routingKey, Object message) {
        template.convertAndSend(exchange, routingKey, message);
    }

    /**
     * 发送到指定队列中
     * @param queueName
     * @param message
     */
    public static void sendToQueue(String queueName, Object message) {
        template.convertAndSend(queueName, message);
    }
}
